package logic

import (
	"context"
	"user-good/model/mysql"

	"user-good/productrpc/internal/svc"
	"user-good/productrpc/productrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodAddLogic {
	return &GoodAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商品添加
func (l *GoodAddLogic) GoodAdd(in *productrpc.GoodAddRequest) (*productrpc.GoodAddResponse, error) {
	// todo: add your logic here and delete this line

	good := &mysql.Good{
		GoodName:   in.GoodName,
		GoodPrice:  float64(in.GoodPrice),
		GoodStatus: in.GoodStatus,
		UserID:     int(in.UserId),
	}

	err := good.CreateGood(mysql.DB)
	if err != nil {
		return nil, err
	}

	return &productrpc.GoodAddResponse{
		GoodId: int64(good.ID),
	}, nil
}
